<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('产品外包往返记录列表')" />
    <th:block th:include="include :: bootstrap-editable-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                批号：
                                <input type="text" name="lotId"/>
                            </li>
                            <li>
                                产品名称：
                                <input type="text" name="partName"/>
                            </li>
                            <li class="select-time">
                                <label style="width: 100px;">申请外包日期：</label>
                                <input type="text" class="time-input" placeholder="开始时间" name="oqcDateBegin" style="width: 100px;"/>
                                <span>~</span>
                                <input type="text" class="time-input" placeholder="结束时间" name="oqcDateEnd" style="width: 100px;"/>
                            </li>
                            <li class="select-time">
                                <label>发货日期：</label>
                                <input type="text" class="time-input" placeholder="发货开始日期" name="deliveryDateBegin" style="width: 100px;"/>
                                <span>~</span>
                                <input type="text" class="time-input" placeholder="发货结束日期" name="deliveryDateEnd" style="width: 100px;"/>
                            </li>
                            <li>
                                当前状态：
                                <select id="poStatus" name="poStatus" th:with="type=${@dict.getType('po_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="outsource:partoutsourcecomegorecord:add">
                    <i class="fa fa-plus"></i> 批量添加
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="outsource:partoutsourcecomegorecord:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-primary multiple disabled" onclick="posconfirm()" shiro:hasPermission="outsource:partoutsourcecomegorecord:edit">
                    <i class="fa fa-edit"></i> 确认信息录入
                </a>
                <a class="btn btn-warning" onclick="scanDeliveryConfirm()" shiro:hasPermission="outsource:partoutsourcecomegorecord:scandeliveryconfirm">
                    <i class="fa fa-check"></i> 扫码发货确认
                </a>
                <a class="btn btn-warning" onclick="selectDeliveryConfirm()" shiro:hasPermission="outsource:partoutsourcecomegorecord:selectdeliveryconfirm">
                    <i class="fa fa-check"></i> 发货确认
                </a>
                <a class="btn btn-info multiple disabled" onclick="receiveConfirm()" shiro:hasPermission="outsource:partoutsourcecomegorecord:receiveconfirm">
                    <i class="fa fa-check"></i> 一次性全部返回确认
                </a>
                <a class="btn btn-success single disabled" onclick="partialBackConfirm()" shiro:hasPermission="outsource:pospbackrecord:partbackconfirm">
                    <i class="fa fa-check"></i> 分批次返回确认
                </a>
                <a class="btn btn-success single disabled" onclick="scrapOutside()" shiro:hasPermission="outsource:pospbackrecord:scrapoutside">
                    <i class="fa fa-check"></i> 在外报废
                </a>
                <a class="btn btn-inverse" onclick="$.table.exportExcel()" shiro:hasPermission="outsource:partoutsourcecomegorecord:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped" style="white-space: nowrap;">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-table-editable-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('outsource:partoutsourcecomegorecord:edit')}]];
        var removeFlag = [[${@permission.hasPermi('outsource:partoutsourcecomegorecord:remove')}]];
        var os_appoint_site = [[${@dict.getType('os_appoint_site')}]];
        var po_status = [[${@dict.getType('po_status')}]];
        var isOqcManager = [[${isOqcManager}]];
        var prefix = ctx + "outsource/partoutsourcecomegorecord";
        // 获取传入的外包角色
        var osrole = [[${osrole}]];

        var column = [
            {
                checkbox: true
            },
            {
                field: 'id',
                title: 'UUID',
                visible: false
            },
            {
                field: 'lotId',
                title: '批号',
                width: 80
            },
            {
                field: 'partType',
                title: '产品类型',
                width: 100
            },
            {
                field: 'partName',
                title: '产品名称',
                width: 200,
                sortable: true
            },
            {
                field: 'customerCode',
                title: '客户编码',
                width: 200,
                sortable: true,
                visible: false
            },
            {
                field: 'outsourceStep',
                title: '外包工步',
                width: 200,
                sortable: true
            },
            {
                field: 'outsourceSeq',
                title: '当前外包次号',
                width: 200
            },
            {
                field: 'seq',
                title: '当前工步',
                width: 200,
                visible: false
            },
            // {
            //     field: 'outsourceStep',
            //     title: '外包工步',
            //     width: 200
            // },
            {
                field: 'outsourceCount',
                title: '外包片数',
                width: 50
            },
            {
                field: 'chipNumber',
                title: '片号',
                width: 80
            },
            {
                field: 'oqcDate',
                title: '申请外包日期',
                width: 120,
                sortable: true
            },
            {
                field: 'deliveryDate',
                title: '发货日期',
                width: 120,
                sortable: true
            },
            {
                field: 'returnCount',
                title: '返回片数',
                width: 80,
                sortable: true
            },
            {
                field: 'actualReturnDate',
                title: '实际返回日期',
                width: 120,
                sortable: true
            },
            {
                field: 'outsourceCycleTime',
                title: '外包周期',
                width: 80
            },
            {
                field: 'sentOutsourceCycleTime',
                title: '已送外包周期',
                width: 80,
                sortable: true
            },
            {
                field: 'appointSite',
                title: '指定场所',
                width: 80,
                formatter: function(value, row, index) {
                    return $.table.selectDictLabel(os_appoint_site, value);
                },
                sortable: true
            },
            {
                field: 'expressNumber',
                title: '快递单号',
                width: 150
            },
            {
                field: 'poStatus',
                title: '当前状态',
                width: 80,
                formatter: function(value, row, index) {
                    return $.table.selectDictLabel(po_status, value);
                }
            },
            {
                field: 'planReturnDate',
                title: '预计返回日期',
                width: 120
            },
            {
                field: 'planOutsourceCycleTime',
                title: '预计外包周期',
                width: 80
            },
            {
                field: 'issueNotes',
                title: '外包前检验备注',
                width: 80
            }
        ];
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "产品外包往返记录",
            columns: column,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: true,
            sortName: "oqcDate",
            sortOrder: "desc",
            sidePagination: "client"
        };

        $(function() {
            setPoStatus();
            $.table.init(options);
        });

        // 根据登录用户的角色，设置外包状态的默认选择
        function setPoStatus() {
            var selectElement = document.getElementById('poStatus');
            // 设置默认选中
            if (osrole === 'warehouse') {
                selectElement.selectedIndex = 2;
            } else if (osrole === 'sale') {
                selectElement.selectedIndex = 1;
            }
        }

        // 状态确认
        function posconfirm() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            var url = prefix + "/isposinit";
            var data = { "ids": rows.join() };
            var ajaxconfig = {
                url: url,
                type: "post",
                dataType: "json",
                data: data,
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍候...");
                },
                success: function(result) {
                    if (null === result) {
                        return;
                    }
                    if (result.code === web_status.SUCCESS) {
                        $.operate.edit();
                    } else if (result.code === web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                complete: function () {
                    $.modal.closeLoading();
                }
            };
            $.ajax(ajaxconfig);
        }

        // 部分返回确认
        function partialBackConfirm() {
            var row = $("#bootstrap-table").bootstrapTable('getSelections')[0];
            if ($.common.isEmpty(row)) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            // 弹窗请求确认
            var url = ctx + "/outsource/partospartialbackrecord" + "/partbackconfirm" + "?applyNo=" + row.id + "&lotId=" + row.lotId;
            $.modal.open("分批次返回确认页面" , url);
        }

        /** 在外报废 **/
        function scrapOutside() {
            var row = $("#bootstrap-table").bootstrapTable('getSelections')[0];
            if ($.common.isEmpty(row)) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            var url = ctx + "/outsource/partospartialbackrecord" + "/scrapoutside" + "?applyNo=" + row.id + "&lotId=" + row.lotId;
            $.modal.open("在外报废页面" , url);
        }

        // 扫码发货确认
        function scanDeliveryConfirm() {
            // 弹窗请求确认
            var url = prefix + "/scandeliveryconfirm";
            $.modal.open("扫码发货确认页面" , url);
        }

        // 选择发货确认
        function selectDeliveryConfirm() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("请确认发货?", function() {
                var url = prefix + "/selectdeliveryconfirm";
                var data = { "ids": rows.join() };
                $.operate.submit(url, "post", "json", data);
            });
        }

        // 到货确认
        function receiveConfirm() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("请确认每卡返回片数与发货片数一致?", function() {
                var url = prefix + "/receiveconfirm";
                var data = { "ids": rows.join() };
                $.operate.submit(url, "post", "json", data);
            });
        }
    </script>
</body>
</html>